package edu.hubu.service.impl;

import java.util.List;

import edu.hubu.dao.UserDao;
import edu.hubu.dao.impl.UserDaoImpl2;
import edu.hubu.exception.IdIsNullException;
import edu.hubu.model.Users;
import edu.hubu.service.UserService;
import edu.hubu.util.Base64Encoder;

public class UserServiceImpl implements UserService {

    private UserDao userDao = new UserDaoImpl2();//依赖注入

    @Override
    public int addUser(Users users) {
        users.setPwd(Base64Encoder.encode(users.getPwd()));
        return userDao.addUser(users);
    }

    @Override
    public int delUserById(Integer id) throws IdIsNullException {
        return userDao.delUserById(id);
    }

    @Override
    public int updateById(Users users) throws IdIsNullException {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Users getUserByName(String name, String pwd) {
        return userDao.getUserByName(name, Base64Encoder.encode(pwd));
    }

    @Override
    public List<Users> getAllUsers() {
        return userDao.getAllUsers();
    }

    @Override
    public List<Users> getPageUsers(int pageNum, int pageSize) {
        return userDao.getPageUsers(pageNum, pageSize);
    }

    @Override
    public int getPageCount(int pageSize) {
        return userDao.getPageCount(pageSize);
    }

}
